# -*- coding: utf-8 -*-
"""
Created on Tue Dec 01 15:17:30 2015

@author: liliangrong
"""
import urllib2
import cookielib

filename = 'cookie.txt'
#'声明一个CookielibJar对象实例来保存cookie'
cookie = cookielib.MozillaCookieJar(filename)
#利用urllib2库的HTTPCookieProcessor对象来创建cookie处理器
handler = urllib2.HTTPCookieProcessor(cookie)
#通过handler来构建opener
opener = urllib2.build_opener(handler)
#此处的open方法同urllib2的urlopen方法，也可以传入request
reponse = opener.open('http://www.baidu.com')

"""
ignore_discard: save even cookies set to be discarded. 
ignore_expires: save even cookies that have expiredThe file is overwritten if it already exists
"""
cookie.save(ignore_discard=True,ignore_expires=True)

